﻿using System;
using System.Runtime.Remoting.Messaging;
using Ledict.ConditionExtract.DAL;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Ledict.ConditionExtract.IDAL;
using Microsoft.Practices.ServiceLocation;

namespace Ledict.ConditionExtract.BLL
{
    /// <summary>
    /// Tree逻辑类
    /// </summary>
    public class TreeDataBLL
    {
        TreeDateDAL trdal = new TreeDateDAL();
        public TreeDataBLL()
        {
            //getter = ServiceLocator.Current.GetInstance<IServiceGetter>();
            ////trdal = new Lazy<ITreeDateDAL>(getter.Get<ITreeDateDAL>);
            //trdal = getter.Get<ITreeDateDAL>();
        }


        #region  第一棵树
        /// <summary>
        /// 得到节点的下级
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public DataTable NodeTree_Tree(string pid)
        {
            return trdal.NodeTree_Tree(pid.Trim());
        }

        public DataTable GetSourceTree(string pid)
        {
            return trdal.GetSourceTree(pid.Trim());
        }

        /// <summary>
        /// 得到节点的下级(SYS_CaseType_DocType) add by zhangpeng 2016-09-12 
        /// </summary>
        /// <param name="ctCode"></param>
        /// <param name="cdDocType"></param>
        /// <param name="cdFileType"></param>
        /// <returns></returns>
        public DataTable GetSourceTree_New(string condition)
        {
            return trdal.GetSourceTree_New(condition);
        }

        /// <summary>
        /// 下级来源树
        /// </summary>
        /// <param name="pId">父ID</param>
        /// <param name="level">层级,默认是1</param>
        /// <returns></returns>
        public DataTable GetSourceTreeChild(string pId, int level = 1)
        {
            return trdal.GetSourceTreeChild(pId, level);
        }


        public int GetChildType(string pid, int ptype, int TableName)
        {
            return trdal.GetChildType(pid.Trim(), ptype, TableName);
        }


        #endregion
        #region 第二颗树
        /// <summary>
        /// 得到节点的下级
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public DataTable GetCauseTree_Two(string pid, int effective)
        {
            return trdal.GetCauseTree_Two(pid.Trim(), effective);
        }

        public DataTable GetCauseTreeTwo_ToExpressTab(string pid, int effective)
        {
            return trdal.GetCauseTreeTwo_ToExpressTab(pid.Trim(), effective);
        }
        public DataTable GetCauseTreeCombineExpress(string pid)
        {
            return trdal.GetCauseTreeCombineExpress(pid);
        }
        public DataTable GetCauseTreeTwo_ToExpressTab_Virtual(string pid, int CC_IsCombination)
        {
            return trdal.GetCauseTreeTwo_ToExpressTab_Virtual(pid.Trim(), CC_IsCombination);
        }

        public DataTable GetCauseTreeThree_ToExpressTab_Virtual(string pid, int CC_IsCombination)
        {
            return trdal.GetCauseTreeThree_ToExpressTab_Virtual(pid.Trim(), CC_IsCombination);
        }

        #endregion
        /// <summary>
        /// 案由树
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public DataTable GetTreeHeadWords(string pid, string Tname)
        {
            return trdal.GetTreeHeadWords(pid.Trim(), Tname);
        }

        public string GetHeadWordAllPid(string headword)
        {
            return trdal.GetHeadWordAllPid(headword);
        }

        /// <summary>
        /// 根据案由ID字符串，获取案由的所有父级节点列表 add by zhangpeng
        /// </summary>
        /// <param name="headwords">案由ID字符串，eg：1181,1655</param>
        /// <returns></returns>
        public List<string> GetheadWordPids(string headwords)
        {
            if (string.IsNullOrEmpty(headwords)) return null;
            var dt = trdal.GetHeadWordAllPids(headwords);
            if (dt != null && dt.Rows.Count > 0)
            {
                return (from DataRow row in dt.Rows select row[0].ToString()).ToList();
            }
            return null;
        }


        /// <summary>
        /// 节点查询
        /// </summary>
        /// <param name="FirPid">查询范围（刑事节点下的）</param>
        /// <param name="name">查询词</param>
        /// <param name="TreeNumber">查询表1：节点树界面;2数据处理界面及表述库界面</param>
        /// <returns></returns>
        public DataTable NodeTree_Query(string FirPid, string name, int TreeNumber)
        {
            return trdal.NodeTree_TreeQuery(FirPid, name.Trim(), TreeNumber);
        }
        /// <summary>
        ///  得到节点所有上级
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetAllParentNode(string id)
        {
            return trdal.GetAllParentNode(id);

        }

        /// <summary>
        /// 根据父节点，获取案例类别
        /// </summary>
        /// <param name="parentId">父节点</param>
        /// <returns></returns>
        public DataTable GetCaseCategorys(string parentId)
        {
            return trdal.GetCaseCategory(parentId);
        }

        /// <summary>
        /// 根据节点名称，获取当前节点及所有子节点
        /// </summary>
        /// <param name="ccName">节点名称</param>
        /// <returns></returns>
        public DataTable AllGetCaseCause(string ccName)
        {
            return trdal.AllGetCaseCause(ccName);
        }

        /// <summary>
        /// 根据CCID，获取当前节点及所有子节点
        /// </summary>
        /// <param name="ccName">节点名称</param>
        /// <returns></returns>
        public DataTable AllGetCaseCauseByCCID(string ccId)
        {
            return trdal.AllGetCaseCauseByCCID(ccId);
        }

        /// <summary>
        /// 根据案例数据库的文书类型
        /// </summary>
        /// <returns></returns>
        public DataTable GetCaseProperty()
        {
            return new TreeDateDAL().GetCaseProperty();
        }

    }
}
